<?php declare(strict_types=1);


namespace App\Services;

use App\Api\Controllers\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class PassVerifyService
{

    public static function pass(Request $request, BaseController $that, callable $callable = null): void
    {
        $pash = $request->path();
        $pass = $request->get('pass', '');
        $pass = substr(base64_decode($pass), 0, -5);

        $pass_verify = $that->pass_verify($pass, $pash); // 密钥验证
        $pass_verify = json_decode($pass_verify, true);
        if ($pass_verify['status'] == '1') {
            $remark = "";
            if (is_callable($callable)) {
                $remark = $callable();
            }
            $pass_id = DB::table('pass')->where(['pass' => $pass])->value('id'); // 密钥id
//            $remark = '门店开通通道: 门店id: ' . $Store_id . '通道id为: ' . $type;
            $that->operation_log($that->parseToken()->user_id, 5, $remark, $pass_id);
        } else {
            throw new \Exception("验证不通过");
//            return json_encode(['status' => 2, 'message' => '验证不通过', 'data' => []]);
        }
    }

}